<template>
	<view class="gardens-xcjh-index">
		<view class="uni-padding-wrap">
			<uni-segmented-control :current="current" :values="items" :style-type="styleType"
				:active-color="activeColor" @clickItem="onClickItem" />
		</view>
		<view class="">
			<uni-card v-for="item in patrolEnter" :key="item.id" v-if="current === 0">
				<view style="display: flex;justify-content: space-between;align-items: center;">
					<view>{{item.planName}}</view>
					<uni-tag style="width: 100rpx;text-align: center;" @click="gopath(item)" text="录入"
						:inverted="true"></uni-tag>
				</view>
			</uni-card>
			<uni-card v-for="item in fulfillPatrol" :key="item.id" v-if="current === 1">
				<view style="display: flex;justify-content: space-between;align-items: center;">
					<view>{{item.planName}}</view>
					<uni-tag style="width: 100rpx;text-align: center;" @click="gopath(item)" text="查看"
						:inverted="true"></uni-tag>
				</view>
			</uni-card>
		</view>
		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
	</view>
</template>

<script>
	import {
		queryPatrolEnter,
		queryFulfillPatrol
	} from "@/api/comp/patrolPlan";
	export default {
		data() {
			return {
				current: 0,
				items: ['待巡查计划', '已完成巡查计划'],
				is_active: 'richang',
				activeColor: 'rgb(35, 89, 193)',
				styleType: 'button',
				date: new Date(),
				patrolEnter: [],
				fulfillPatrol: [],
				status: 'noMore',
				reload: false,
				queryParams: {},
				page: 1,
				size: 10,
				total: 0,
				total2: 0,
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
			}
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			this.page++;
			if (this.current == 0) {
				if (this.patrolEnter.length < this.total) {
					this.status = 'more';
				} else {
					this.status = 'noMore';
					return;
				}
				this.getList();
			} else {
				if (this.fulfillPatrol.length < this.total2) {
					this.status = 'more';
				} else {
					this.status = 'noMore';
					return;
				}
				this.getMaintainSpecialPlan();
			}
		},
		methods: {
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
					this.patrolEnter = [];
					this.fulfillPatrol = [];
					this.page = 1;
					this.reload = true;
					this.getList();
				}
			},
			getList() {
				if (this.current == 0) {
					queryPatrolEnter(Object.assign(this.queryParams,{planStatus: "1",})).then(res => {
						uni.showLoading({
							title: "加载中"
						})
						if (this.total && !this.reload) {
							//说明已有数据，目前处于上拉加载
							this.status = 'loading';
						}
						if (this.reload) {
							uni.stopPullDownRefresh();
						}
						this.queryParams.pageSize = this.size;
						this.queryParams.pageNum = this.page;
						if(res.rows){
							uni.hideLoading();
							this.total = res.total;
							this.patrolEnter = this.reload ? res.rows : this.patrolEnter.concat(res.rows);
							this.reload = false;
						}
					})

				} else {
					queryFulfillPatrol(this.queryParams).then(res => {
						uni.showLoading({
							title: "加载中"
						})
						if (this.total2 && !this.reload) {
							//说明已有数据，目前处于上拉加载
							this.status = 'loading';
						}
						if (this.reload) {
							uni.stopPullDownRefresh();
						}
						this.queryParams.pageSize = this.size;
						this.queryParams.pageNum = this.page;
						if(res.rows){
							uni.hideLoading();
							this.total2 = res.total;
							this.fulfillPatrol = this.reload ? res.rows : this.fulfillPatrol.concat(res.rows);
							this.reload = false;
						}
						
						
					})
				}
			},
			backClick() {
				uni.navigateBack()
			},
			gopath(row) {
				if (this.current == 0) {
					uni.navigateTo({
						url: '/pages/gardens/xcjh/report?id=' + row.id
					})
				}
				if (this.current == 1) {
					uni.navigateTo({
						url: '/pages/gardens/xcjh/view?id=' + row.id
					})
				}

			},
		}
	}
</script>

<style lang="scss">
	$nav-height: 30px;

	.box-bg {
		background-color: #F5F5F5;
		padding: 5px 0;
	}

	.city {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		justify-content: flex-start;
		// width: 160rpx;
		margin-left: 4px;
	}

	.input-uni-icon {
		line-height: $nav-height;
	}

	.gardens-xcjh-index {
		.gradens-yhrw-btn {
			display: flex;

			button {
				width: 50%;
			}

			.is_active {
				background-color: #0055ff;
				color: #F5F5F5;
			}

			.no_active {
				background-color: #F5F5F5;
				color: #000;
			}
		}

		.gradens-yhrw-card {
			.yhrw-list-item {
				display: flex;

				.yhrw-list-name {
					width: 125rpx;
				}

				.yhrw-list-text {
					flex: 1;

				}
			}
		}
	}
</style>